package com.fs.ssm004.controller;


import com.fs.ssm004.pojo.Teacher;
import com.fs.ssm004.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @RequestMapping("/login")
    @ResponseBody//自动转成json字符串
    public Map<String, Object> login(String teacherName, String password) {
        Map<String, Object> result = new HashMap<>();
        if (teacherName != null && !teacherName.equals("") && password != null && !password.equals("")) {
            return teacherService.login(teacherName, password);
        }
        result.put("code", -1);
        result.put("message", "用户输入异常");
        return result;
    }


    @RequestMapping("/view1")
    public String view1() {
        return "page";
    }
    @RequestMapping("/view2")
    public String view2() {
        return "tpage";
    }
    @RequestMapping("/view3")
    public String view3() {
        return "ttpage";
    }
    @RequestMapping("/logout")
    public String logout(HttpServletResponse response) {
        Teacher teacher = teacherService.logout();
        return "redirect:/login.jsp";
    }


}
